package com.ch.home.service.serviceImpl.restDishServiceImpl;

import com.ch.home.bean.RestDish;
import com.ch.home.bean.Restaurant;
import com.ch.home.mapper.restDishMapper.RestaurantMapper;
import com.ch.home.service.serviceInterface.restDishService.RestaurantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;

/**
 * Created by CHEN on 2019/9/4.
 */
@Service
public class RestaurantServiceImpl implements RestaurantService {

    @Autowired
    RestaurantMapper restaurantMapper;

    @Override
    public HashMap insertRestaurantInfo(Restaurant restaurant) {

        HashMap<Object, Object> result = new HashMap<>( );

        int re = restaurantMapper.insertRestInfo(restaurant);
        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        return result;
    }

    @Override
    public HashMap updateRestaurantInfo(Restaurant restaurant) {
        HashMap<Object, Object> result = new HashMap<>( );

        int re = restaurantMapper.updateRestInfo(restaurant);
        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        return result;
    }

    @Override
    public HashMap insertRestDishInfo(RestDish restDish) {

        HashMap<Object, Object> result = new HashMap<>( );

        int re = restaurantMapper.insertRestDishInfo(restDish);
        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        return result;
    }

    @Override
    public HashMap updateRestDishInfo(RestDish restDish) {
        HashMap<Object, Object> result = new HashMap<>( );

        int re = restaurantMapper.updateRestDishInfo(restDish);
        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        return result;
    }

    @Override
    public HashMap insertMulRestDishInfo(LinkedList<RestDish> list) {
        HashMap<Object, Object> result = new HashMap<>( );

        int re = restaurantMapper.insertMulRestDishInfo(list);
        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        return result;
    }

    @Override
    public HashMap getRestaurantList(Restaurant restaurant) {
        HashMap<Object, Object> result = new HashMap<>( );

        LinkedList<Restaurant> restaurantList = restaurantMapper.getRestaurantList(restaurant);
        if (restaurantList.size( ) > 0) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        result.put("value", restaurantList);
        return result;
    }

    @Override
    public HashMap getRestaurantById(Restaurant restaurant) {


        HashMap<Object, Object> result = new HashMap<>( );

        Restaurant restaurantResult = restaurantMapper.getRestaurantById(restaurant);
        if (restaurantResult!=null) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        result.put("value", restaurantResult);
        return result;

    }
}
